/*
MockO: FuDePAN's Mocking Operations
    Copyright (C) 2012  Daniel Gutson, FuDePAN

    This file is part of MockO.

    MockO is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MockO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MockO.  If not, see <http://www.gnu.org/licenses/>.

    This is the file that contains the tests.
*/

#include <stdio.h>
#include <gtest/gtest.h>

#include "mocko_bind.h"

using ::testing::Return;

// this is optional
void mocko_pre_tests(void)
{
    printf("mocko_pre_tests\n");
}

// this is optional too
void mocko_post_tests(void)
{
    printf("mocko_post_tests\n");
}

TEST(ExampleSuite, ZeroTest_OK)
{
    ASSERT_EQ(0, functionToTest(0));
}

TEST(ExampleSuite, ZeroTest_FAIL)
{
    EXPECT_CALL(mocko, functionToMock1(0)).WillOnce(Return(0));
    enableMock_functionToMock1();       // magic occurs here
    EXPECT_NE(0, functionToTest(0));
    disableMock_functionToMock1();      // and here
}

TEST(ExampleSuite, NegativeTest)
{
    ASSERT_EQ(-2, functionToTest(-1));
}

TEST(ExampleSuite, PositiveTest)
{
    ASSERT_EQ(2, functionToTest(1));
}

TEST(ExampleSuite, StringTest_OK)
{
    ASSERT_EQ(42, functionToTest2("The Ultimate Question"));
}

TEST(ExampleSuite, StringTest_MOCKED)
{
    EXPECT_CALL(mocko, functionToMock3("123456789012345678901")).WillOnce(Return(41));
    enableMock_functionToMock3();
    ASSERT_EQ(41, functionToTest2("The Wrong Question"));
    disableMock_functionToMock3();
}

TEST(ExampleSuite, void_OK)
{    
    ASSERT_EQ(42, functionToTest3());
}

TEST(ExampleSuite, void_MOCKED)
{
    // Hugo: how to mock functionToMock4? :)
    EXPECT_CALL(mocko, functionToMock5()).WillOnce(Return(42));
    enableMock_functionToMock5();
    ASSERT_NE(42, functionToTest3());
    disableMock_functionToMock5();
}

TEST(ExampleSuite, malloc_OK)
{
    ASSERT_EQ(0, strcmp("The answer is 42", functionToTest4()));
}

TEST(ExampleSuite, malloc_MOCKED)
{
    EXPECT_CALL(mocko, malloc(sizeof("The answer is 42"))).WillOnce(Return(((void*)0)));
    enableMockTimes_malloc(0, 1);
    ASSERT_EQ(NULL, functionToTest4());
    disableMock_malloc();
}

TEST(ExampleSuite, EnumTest_OK)
{
    ASSERT_EQ(42, functionToTest5());
}

TEST(ExampleSuite, EnumTest_MOCKED)
{
    EXPECT_CALL(mocko, functionToMock6(RightAnswer)).WillOnce(Return(43));
    enableMock_functionToMock6();
    ASSERT_EQ(43, functionToTest5());
    disableMock_functionToMock6();
}

